﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;


namespace TSPquestEDITOR
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            string search_name = basic_info.multi_quest_search_name;

            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string connectionString = config.ConnectionStrings.ConnectionStrings["conn"].ConnectionString.ToString();

            //Define Connection
            SqlConnection qCon = new SqlConnection(connectionString);
            //Open Connection
            qCon.Open();

            string strSQL = "SELECT QRES.id, SRES.value as name, QRES.limit_level as 'Level Req' FROM dbo.StringResource SRES INNER JOIN dbo.QuestResource QRES on QRES.text_id_quest = SRES.code WHERE SRES.VALUE LIKE '%" + search_name + "%' ORDER BY QRES.id ASC";
 
            SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, qCon);
            SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
 
            // Populate a new data table and bind it to the BindingSource.
            DataTable table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataAdapter.Fill(table);
            bindSource.DataSource = table;
 
            // Resize the DataGridView columns to fit the newly loaded content.
            dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.Fill);
            // you can make it grid readonly.
            dataGridView.ReadOnly = true; 
            // finally bind the data to the grid
            dataGridView.DataSource = bindSource;

        }

        private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = dataGridView.CurrentCell.OwningRow;
            string returned_val = row.Cells["id"].Value.ToString();
            basic_info.multi_quest_search_return_id = returned_val.ToString();

            basic_info basic = new basic_info();

            this.Dispose();
        }

    }
}
